#!/bin/bash

# data_dir
datadir=/var/www/html

if [ ! -d ${datadir} ]; then
	UUID=$(mdata-get sdc:uuid)
	DDS=zones/${UUID}/data

	if zfs list ${DDS} 1>/dev/null 2>&1; then
		zfs create ${DDS}/nextcloud || true

		zfs set mountpoint=${datadir} ${DDS}/nextcloud

		# znapzend for backup
		znapzendzetup create --recursive --tsformat='%Y-%m-%d-%H%M%S' --donotask \
			SRC '7day=>8hour,30day=>1day,1year=>1week,10year=>1month' ${DDS}
		/usr/sbin/svcadm enable svc:/pkgsrc/znapzend:default
	else
		mkdir -p ${datadir}
	fi
fi

[[ -d ${datadir}/config ]] || cp -r /opt/local/share/nextcloud/* ${datadir}

chown -R www:www ${datadir}